﻿using HttpClientLite.Handlers.interfaces;
using System.Net.Http;

namespace HttpClientLite.Extensions;

internal class HttpManagerExceptionHandlerMethod(Action<Exception, HttpResponseMessage?> handlerMethod) : IHttpManagerExceptionHandler
{
    public void Handle(Exception exception, HttpResponseMessage? responseMessage)
    {
        handlerMethod(exception, responseMessage);
    }
}

internal class ResponseMessageHandlerMethod(Func<HttpManagerBase, HttpClient, HttpRequestMessage, CancellationToken?, Task<HttpResponseMessage>> handlerMethod) : IResponseMessageHandler
{
    public async Task<HttpResponseMessage> HandleAsync(HttpManagerBase httpManager,
                                                       HttpClient httpClient,
                                                       HttpRequestMessage cloneHttpRequest,
                                                       HttpResponseMessage httpResponseMessage,
                                                       CancellationToken? cancellationToken = null)
    {
        return await handlerMethod(httpManager, httpClient, cloneHttpRequest, cancellationToken);
    }
}